/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package TapestryModel.impl;

import TapestryModel.Attribute;
import TapestryModel.ContentObject;
import TapestryModel.LinkMapping;
import TapestryModel.ParamLink;
import TapestryModel.TapestryModelPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Param Link</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link TapestryModel.impl.ParamLinkImpl#getOwner <em>Owner</em>}</li>
 *   <li>{@link TapestryModel.impl.ParamLinkImpl#getLabelRef <em>Label Ref</em>}</li>
 *   <li>{@link TapestryModel.impl.ParamLinkImpl#getParam <em>Param</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ParamLinkImpl extends LinkImpl implements ParamLink {

    @Override
    public String getLinkLabel() {
        if(getLabelRef()!=null)
            return getLabelRef().getName();

        return super.getLabel();
    }

    /**
     * The cached value of the '{@link #getLabelRef() <em>Label Ref</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getLabelRef()
     * @generated
     * @ordered
     */
    protected Attribute labelRef;

    /**
     * The cached value of the '{@link #getParam() <em>Param</em>}' containment reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getParam()
     * @generated
     * @ordered
     */
    protected EList<LinkMapping> param;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected ParamLinkImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return TapestryModelPackage.Literals.PARAM_LINK;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ContentObject getOwner() {
        if (eContainerFeatureID != TapestryModelPackage.PARAM_LINK__OWNER) return null;
        return (ContentObject)eContainer();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetOwner(ContentObject newOwner, NotificationChain msgs) {
        msgs = eBasicSetContainer((InternalEObject)newOwner, TapestryModelPackage.PARAM_LINK__OWNER, msgs);
        return msgs;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setOwner(ContentObject newOwner) {
        if (newOwner != eInternalContainer() || (eContainerFeatureID != TapestryModelPackage.PARAM_LINK__OWNER && newOwner != null)) {
            if (EcoreUtil.isAncestor(this, newOwner))
                throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
            NotificationChain msgs = null;
            if (eInternalContainer() != null)
                msgs = eBasicRemoveFromContainer(msgs);
            if (newOwner != null)
                msgs = ((InternalEObject)newOwner).eInverseAdd(this, TapestryModelPackage.CONTENT_OBJECT__LINK, ContentObject.class, msgs);
            msgs = basicSetOwner(newOwner, msgs);
            if (msgs != null) msgs.dispatch();
        }
        else if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.PARAM_LINK__OWNER, newOwner, newOwner));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Attribute getLabelRef() {
        if (labelRef != null && labelRef.eIsProxy()) {
            InternalEObject oldLabelRef = (InternalEObject)labelRef;
            labelRef = (Attribute)eResolveProxy(oldLabelRef);
            if (labelRef != oldLabelRef) {
                if (eNotificationRequired())
                    eNotify(new ENotificationImpl(this, Notification.RESOLVE, TapestryModelPackage.PARAM_LINK__LABEL_REF, oldLabelRef, labelRef));
            }
        }
        return labelRef;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Attribute basicGetLabelRef() {
        return labelRef;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setLabelRef(Attribute newLabelRef) {
        Attribute oldLabelRef = labelRef;
        labelRef = newLabelRef;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.PARAM_LINK__LABEL_REF, oldLabelRef, labelRef));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public EList<LinkMapping> getParam() {
        if (param == null) {
            param = new EObjectContainmentEList<LinkMapping>(LinkMapping.class, this, TapestryModelPackage.PARAM_LINK__PARAM);
        }
        return param;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                if (eInternalContainer() != null)
                    msgs = eBasicRemoveFromContainer(msgs);
                return basicSetOwner((ContentObject)otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                return basicSetOwner(null, msgs);
            case TapestryModelPackage.PARAM_LINK__PARAM:
                return ((InternalEList<?>)getParam()).basicRemove(otherEnd, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
        switch (eContainerFeatureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                return eInternalContainer().eInverseRemove(this, TapestryModelPackage.CONTENT_OBJECT__LINK, ContentObject.class, msgs);
        }
        return super.eBasicRemoveFromContainerFeature(msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                return getOwner();
            case TapestryModelPackage.PARAM_LINK__LABEL_REF:
                if (resolve) return getLabelRef();
                return basicGetLabelRef();
            case TapestryModelPackage.PARAM_LINK__PARAM:
                return getParam();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                setOwner((ContentObject)newValue);
                return;
            case TapestryModelPackage.PARAM_LINK__LABEL_REF:
                setLabelRef((Attribute)newValue);
                return;
            case TapestryModelPackage.PARAM_LINK__PARAM:
                getParam().clear();
                getParam().addAll((Collection<? extends LinkMapping>)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                setOwner((ContentObject)null);
                return;
            case TapestryModelPackage.PARAM_LINK__LABEL_REF:
                setLabelRef((Attribute)null);
                return;
            case TapestryModelPackage.PARAM_LINK__PARAM:
                getParam().clear();
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.PARAM_LINK__OWNER:
                return getOwner() != null;
            case TapestryModelPackage.PARAM_LINK__LABEL_REF:
                return labelRef != null;
            case TapestryModelPackage.PARAM_LINK__PARAM:
                return param != null && !param.isEmpty();
        }
        return super.eIsSet(featureID);
    }

} //ParamLinkImpl
